package com.edu.xidian.produce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import java.util.UUID;

@Component
public class Queue_Produce {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;


    // 往队列queue中发生消息
    public void produceMsg(){
        jmsMessagingTemplate.convertAndSend(queue,"**********" + UUID.randomUUID().toString().substring(0,6));
    }


    // 定时投递,间隔时间3秒钟定投
    // 在主启动类使用@EnableScheduling   // 激活定时投递方法
    @Scheduled(fixedDelay = 3000)
    public void produceMsgScheduled(){
        jmsMessagingTemplate.convertAndSend(queue,"*****Scheduled*****" + UUID.randomUUID().toString().substring(0,6));
        System.out.println("******produceMsgScheduled send ok********");
    }

}
